/*
 * MIT License
 *
 * Copyright (c) 2020 Mr.css
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 */

package cn.seaboot.openapi;

import cn.seaboot.postman.root.Variable;

/**
 * Postman 基础环境配置，包括：文档名称、后台地址、接口标准等
 *
 * @author Mr.css
 * @version 2020-01-29 15:29
 */
public class Environment {
    /**
     * 文档名称
     */
    private String name = "Doc";
    /**
     * 文档唯一 ID
     */
    private String postmanId;

    /**
     * postman-collection api Version
     */
    private String postmanVersion = "https://schema.getpostman.com/json/collection/v2.1.0/collection.json";
    /**
     * 采用的网络协议
     */
    private String protocol = "http";
    /**
     * IP 地址
     * <p>
     * 一本默认即可，默认使用共享变量
     */
    private String[] host = new String[]{"{{baseUrl}}"};
    /**
     * 端口号
     * <p>
     * 默认情况下，置空即可
     * <p>
     * baseUrl中可以包含端口号，如果选择自定义共享变量，再可以考虑给这个值赋值
     */
    private String port;
    /**
     * 基础路径
     * <p>
     * 一般默认即可
     */
    private String baseUrl = "{{baseUrl}}";
    /**
     * 访问项目接口的地址
     * <p>
     * 项目真实路径，最终会被用于替换 baseUrl
     *
     * 代码中 controller 地址之前的那一部分: http://127.0.0.1:8080/demo
     */
    private String originalUrl;

    /**
     * 共享变量
     *
     * 这直接决定了如何编写代码，优先使用这个配置，如果为空则使用默认的。
     */
    private Variable[] variables;

    public Variable[] defaultVariable() {
        Variable variable = new Variable();
        variable.setId("baseUrl");
        variable.setKey("baseUrl");
        variable.setType("string");
        variable.setValue(this.originalUrl);
        return new Variable[]{variable};
    }

    //getter/setter------------------------------------------------------------------


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPostmanId() {
        return postmanId;
    }

    public void setPostmanId(String postmanId) {
        this.postmanId = postmanId;
    }

    public String getPostmanVersion() {
        return postmanVersion;
    }

    public void setPostmanVersion(String postmanVersion) {
        this.postmanVersion = postmanVersion;
    }

    public String getProtocol() {
        return protocol;
    }

    public void setProtocol(String protocol) {
        this.protocol = protocol;
    }

    public String[] getHost() {
        return host;
    }

    public void setHost(String[] host) {
        this.host = host;
    }

    public String getPort() {
        return port;
    }

    public void setPort(String port) {
        this.port = port;
    }

    public String getBaseUrl() {
        return baseUrl;
    }

    public void setBaseUrl(String baseUrl) {
        this.baseUrl = baseUrl;
    }

    public Variable[] getVariables() {
        return variables;
    }

    public void setVariables(Variable[] variables) {
        this.variables = variables;
    }

    public String getOriginalUrl() {
        return originalUrl;
    }

    public void setOriginalUrl(String originalUrl) {
        this.originalUrl = originalUrl;
    }
}
